<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../docs-assets/ico/favicon.png">

    <title>UPMContact - Déposer votre annonce !</title>

    <!-- Bootstrap core CSS -->
    <link href="../dist/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../dsit/css/signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
  
<!-- NAVBAR
================================================== -->  
    <div class="navbar-wrapper">
      <div class="container">

        <div class="navbar navbar-inverse navbar-static-top" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
            </div>
            <div class="navbar-collapse collapse">
              <ul class="nav navbar-nav">
                <li class="active"><a href="bde.html">Accueil</a></li>
                <li><a href="#about"></a></li>
				<li class="dropdown">
				<a href="#" class="dropdown-toggle" data-toggle="dropdown">Vie Etudiante <b class="caret"></b></a>
				    <ul class="dropdown-menu">
						<li><a href="deposer.html">Déposer une annonce</a></li>
						<li class="divider"></li>
						<li><a href="consulter.html">Consulter les annonces</a></li>
						<li class="divider"></li>
					</ul>
				</li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Compte <b class="caret"></b></a>
                  <ul class="dropdown-menu">
					<li class="dropdown-header"> <div id="user-info" hidden> Enregistré comme  <span id="us"> </span></div> </li>
						<li><a href="#" class="log-out">Déconnexion</a></li>
                    <li class="divider"></li>
                  </ul>
				</li>
              </ul>
            </div>
          </div>
        </div>

      </div>
    </div>

	<!-- ENTER INFORMATION
================================================== -->
    <div class="container">

      <div class="form-deposer" >
        <h2 class="form-deposer-heading">Déposez votre annonce</h2>
		<p> Titre </p>
		<input type="text" id = "deposer-title" class="form-control" placeholder="Titre" required autofocus></br>
		<p> Evènement (ex: soirée, voyage...) </p>
		<input type="text" id = "deposer-eventType" class="form-control" placeholder="Evenement" required autofocus></br>
		<p> Description </p>
		<textarea type="text" id = "deposer-description" class="form-control" rows="3" placeholder="Description" required autofocus> </textarea> </br>		
		<p> Tarif </p>
		<textarea type="text" id = "deposer-additionalInfos" class="form-control" rows="2" placeholder="Tarif" required autofocus> </textarea> </br>	
		<p> Lien URL </p>
		<input type="text" id = "deposer-link" class="form-control" placeholder="URL" required autofocus></br>
		<p> Photo </p>
		<input type="file" id="fileUploader"> </br>
	<!--	<button id="fileUploadBtn">Joindre photo</button>-->
        <!--<label class="checkbox">
          <input type="checkbox" value="remember-me"> Remember me
        </label>-->
        <button id = "button" class="btn btn-lg btn-primary btn-block" >Déposer l'annonce</button>
      </div></br>
		
    </div> <!-- /container -->
	<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="../js/underscore-1.1.6.js"></script>
	<script src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
	<script>
	
	$( document ).ready(function() {
		function getValueSelected(){
					var entries = document.getElementsByTagName("input");
					var i=0;
					var idValue="";
					for(i=0;i<entries.length;i++){
						if(entries[i].checked == true){
							idValue=entries[i].value;
						}
					}
					if(idValue != ""){
						return idValue;
					}
					else{
						return "";
					}
				 }
			 
		Parse.$ = jQuery;
		Parse.initialize("lken7qlOOU6DnGkQddYiIIVTTGBVGt8cHsTh0mN6", "lVOSFDfYALex78xE7WdpLadiZl61hUe1VrbnLA73");

			$("#button").click(function(){
				

				var title = $("#deposer-title").val();
				var eventType = $("#deposer-eventType").val();
				var description = $("#deposer-description").val();
				var additionalInfos = $("#deposer-additionalInfos").val();
				var link = $("#deposer-link").val();
				var fileUploadControl = $("#fileUploader")[0];
				
				var BDEModel = Parse.Object.extend("BDEModel");
				var BDE = new BDEModel();
								
				
				BDE.save(null, {
				success: function(BDE) {
				BDE.set("publishedBy", Parse.User.current());
				BDE.set("title", title);
				BDE.set("eventType", eventType);
				BDE.set("description", description);
				BDE.set("additionalInfos", additionalInfos);
				BDE.set("link", link);

				if (fileUploadControl.files.length > 0) {
					var file = fileUploadControl.files[0];
					var name = "photo.jpg";
					var parseFile = new Parse.File(name, file);
					BDE.set("photo", parseFile);
					parseFile.save().then(function() {
						console.dir(arguments);
					}, function(error) {
						alert("Erreur chargement image");
						console.dir(error);
					});
				}

				BDE.save();
				alert("Annonce déposée avec succès!");
				$("#redirect").show();
				window.setTimeout("location=('bde.html');",1000);				
				 },
				error: function(BDE, error) {
				  alert("enregistrement échoué");
				} 
				});
				 																																					
			 });
	});
	</script>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
	<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="../js/underscore-1.1.6.js"></script>
    
	<script src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
    <script src="../dist/js/bootstrap.min.js"></script>
    <script src="../docs-assets/js/holder.js"></script>
	<script src="../js/logInInfo.js"></script>
  </body>
</html>
